R -*- coding: utf-8 -*-

"""
PyQt5 tutorial 

In this example, we determine the event sender
object.

author: py40.com
last edited: 2017年3月
"""


import sys
from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtWidgets import QMainWindow, QApplication


class Communicate(QObject):
    dispSig = pyqtSignal() 
    

class Example(QMainWindow):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):      
        #创建一个信号
        self.c = Communicate()
        #信号连接到***
        self.c.dispSig.connect(self.getSig)       
        
        self.statusBar()

        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('Emit signal')
        self.show()
        
    def mousePressEvent(self, event):
        #按下鼠标时发出信号
        self.c.dispSig.emit()

    def getSig(self):
        #接收到信号
        self.statusBar().showMessage('Get signal')
        
    
if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

